import mockjs from 'mockjs';
import { delay } from 'roadhog-api-doc';
import defaultSettings from '@/defaultSettings';

const proxy = {
  // 左侧业务组件列表
  'POST /pmc/pcms/formDesigner/queryFormBusiCompList': (req, res) => {
    res.send({
      success: true,
      errMessage: '',
      errCode: '',
      stackTrace: '',
      data: {
        busiCompList: [
          {
            attrId: 0,
            busiObjAttrId: 0,
            busiObjId: '1001',
            span: 24,
            componentType: 'Card',
            eleAttrs: [],
            elementCode: 'SaleOpp',
            elementId: 1001,
            elementName: '商机信息',
            label: '商机信息',
            labelCol: 8,
            name: 'SaleOpp',
            parElementId: 0,
            placeholder: '',
            properties: [
              {
                attrId: '100101',
                busiObjAttrId: 100101,
                busiObjId: 1001,
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppName',
                elementId: 100101,
                elementName: '1-商机名称',
                hintInfo: '请输入商机名称',
                initialValue: '',
                label: '1-商机名称',
                labelCol: 8,
                name: 'SaleOpp_oppName',
                parElementId: 1001,
                placeholder: '请输入商机名称',
                wrapperCol: 16,
              },
              {
                attrId: 100102,
                busiObjAttrId: 100102,
                busiObjId: '1001',
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppCode',
                elementId: 100102,
                elementName: '2-商机编码',
                hintInfo: '',
                initialValue: '',
                label: '2-商机编码',
                labelCol: 8,
                name: 'SaleOpp_oppCode',
                parElementId: 1001,
                placeholder: '请输入商机编码',
                wrapperCol: 16,
              },
              {
                attrId: 100103,
                dataSource: [
                  {
                    attrId: 100103,
                    attrValue: '1100',
                    attrValueDesc: '',
                    attrValueId: 80230,
                    attrValueName: 'ICT商机',
                    attrValueSort: '1',
                    id: 80230,
                    label: 'ICT商机',
                    statusCd: '1000',
                    value: '1100',
                  },
                  {
                    attrId: 100103,
                    attrValue: '2',
                    attrValueDesc: '',
                    attrValueId: 80231,
                    attrValueName: '一般商机',
                    attrValueSort: '2',
                    id: 80231,
                    label: '一般商机',
                    statusCd: '1000',
                    value: '1000',
                  },
                ],
                busiObjAttrId: 100103,
                busiObjId: '1001',
                span: 8,
                componentType: 'Select',
                disabled: false,
                display: true,
                elementCode: 'SaleOpp_oppType',
                elementId: 100103,
                elementName: '3-商机类型',
                hintInfo: '请选择商机类型',
                initialValue: '1000',
                label: '3-商机类型',
                labelCol: 8,
                name: 'SaleOpp_oppType',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                attrId: 100104,
                busiObjAttrId: 100104,
                busiObjId: '1001',
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_custDecisionPost',
                elementId: 100104,
                elementName: '4-客户决策人职位',
                hintInfo: '',
                initialValue: '',
                label: '4-客户决策人职位',
                labelCol: 8,
                name: 'SaleOpp_custDecisionPost',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                attrId: 100105,
                busiObjAttrId: 100105,
                busiObjId: '1001',
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppProfit',
                elementId: 100105,
                elementName: '5-商机收益',
                hintInfo: '',
                initialValue: '',
                label: '5-商机收益',
                labelCol: 8,
                name: 'SaleOpp_oppProfit',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                attrId: 100106,
                busiObjAttrId: 100106,
                busiObjId: '1001',
                componentType: 'NumberPicker',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppAmount',
                elementId: 100106,
                elementName: '6-商机金额',
                hintInfo: '',
                initialValue: '',
                label: '6-商机金额',
                labelCol: 8,
                name: 'SaleOpp_oppAmount',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
            ],
            wrapperCol: 16,
          },
          {
            attrId: 1,
            busiObjAttrId: 1,
            busiObjId: 1002,
            span: 24,
            componentType: 'Card',
            eleAttrs: [],
            elementCode: 'SaleOpp',
            elementId: 1002,
            elementName: '客户信息',
            label: '客户信息',
            labelCol: 8,
            name: 'customer',
            parElementId: 0,
            placeholder: '',
            wrapperCol: 16,
            properties: [
              {
                elementId: 38007,
                componentType: 'Input',
                busiObjAttrId: 10006,
                defaultValue: '',
                display: true,
                extValues: {},
                elementCode: 'customer_instruct',
                statusCd: '1000',
                label: '行业分类',
                parElementId: 38003,
                readOnlyFlag: 1,
                requiredFlag: 0,
                showFlag: 1,
                elementName: '行业分类',
                attrId: 10006,
                busiObjId: 1002,
                name: 'customer_instruct',
                disabled: true,
                initialValue: '',
              },
              {
                elementId: 38021,
                componentType: 'SlickUpload',
                busiObjAttrId: 10020,
                defaultValue: '',
                display: true,
                extValues: {},
                elementCode: 'customer_fileName',
                statusCd: '1000',
                label: '附件名称',
                parElementId: 38002,
                readOnlyFlag: 0,
                requiredFlag: 0,
                showFlag: 1,
                elementName: '附件名称',
                attrId: 10020,
                busiObjId: 1002,
                name: 'customer_fileName',
                disabled: false,
              },
            ],
          },
        ],
        customCompList: [
          {
            label: '审核记录',
            name: 'xx1',
            componentType: 'Async', // 固定值
            path: 'ProcessRecords', // 相对于src\pages\FormDesigner\components\Async\Assets目录
          },
          {
            label: '选择审核人',
            name: 'xx2',
            componentType: 'Async',
            path: 'ObjFlowView',
          },
        ],
      },
    });
  },
  // 获取表单模板数据
  'POST /pmc/pcms/formDesigner/query': (req, res) => {
    res.send({
      success: true,
      errMessage: '',
      errCode: '',
      stackTrace: '',
      data: {
        eleDriveRuleList: [
          {
            driveType: 'calc',
            targetEleCode: 'SaleOpp_oppProfit',
            triggerEleRuleExpr: 'SaleOpp_oppAmount',
            targetEleRuleExpr: 'SaleOpp_oppAmount*2+1',
            ruleName: '【设置值】金额变化联动计算收益',
          },
          {
            targetEleCode: 'SaleOpp_custDecisionPost',
            ruleName: '一般商机【隐藏】客户决策人',
            driveType: 'hide',
            triggerEleRuleExpr: 'SaleOpp_oppType == "1000"',
          },
          {
            ruleName: '输入商机名称，商机编码【必填】',
            targetEleCode: 'SaleOpp_oppCode',
            driveType: 'required',
            triggerEleRuleExpr: 'SaleOpp_oppName != ""',
          },
          {
            driveType: 'setOptions',
            targetEleRuleExpr: 'post("/pmc/pcms/formVersion/queryOptions", SaleOpp_oppType)',
            targetEleCode: 'SaleOpp_select',
            ruleName: '111',
            triggerEleRuleExpr: 'SaleOpp_oppType',
          },
        ],
        elementList: [
          {
            name: 'customer_fileName',
            elementId: 38021,
            componentType: 'ButtonGroup',
            busiObjAttrId: 10020,
            defaultValue: '',
            display: true,
            extValues: {},
            elementCode: 'customer_fileName',
            statusCd: '1000',
            label: '附件名称',
            parElementId: 38002,
            readOnlyFlag: 0,
            requiredFlag: 0,
            showFlag: 1,
            elementName: '按钮组',
            attrId: 10020,
            busiObjId: 1002,
            disabled: false,
            megaProps: {
              span: 1,
            },
            textAlign: 'right',
            isDropdown: false,
            group: [
              {
                label: '新增商机1',
                buttonType: 'default',
                action: '/pmc/pcms/formVersion/confirm',
                method: 'post',
                displayMode: 'iframe',
                viewTitle: '我是弹窗1',
                viewWidth: 1200,
                viewHeight: 800,
                viewUrl: 'https://huaban.com/',
              },
              {
                label: '新增商机2',
                buttonType: 'primary',
                action: '/pmc/pcms/formVersion/confirm',
                method: 'post',
                displayMode: 'iframe',
                viewTitle: '我是弹窗2',
                viewWidth: 800,
                viewUrl: 'https://qq.com/',
              },
            ],
            rules: {},
          },
          {
            attrId: 0,
            busiObjAttrId: 0,
            busiObjId: '1001',
            span: 24,
            componentType: 'Card',
            eleAttrs: [],
            elementCode: 'SaleOpp',
            elementId: 1001,
            elementName: '商机信息',
            label: '商机信息',
            labelCol: 8,
            name: 'SaleOpp',
            parElementId: 0,
            placeholder: '',
            properties: [
              {
                attrId: '100101',
                busiObjAttrId: 100101,
                busiObjId: 1001,
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppName',
                elementId: 100101,
                elementName: '1-商机名称',
                hintInfo: '请输入商机名称',
                initialValue: '',
                label: '1-商机名称',
                labelCol: 8,
                name: 'SaleOpp_oppName',
                parElementId: 1001,
                placeholder: '请输入商机名称',
                wrapperCol: 16,
                rules: {
                  requiredRule: { required: true, whitespace: true, message: '必填项' },
                },
              },
              {
                attrId: 100102,
                busiObjAttrId: 100102,
                busiObjId: '1001',
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppCode',
                elementId: 100102,
                elementName: '2-商机编码',
                hintInfo: '',
                initialValue: '',
                label: '2-商机编码',
                labelCol: 8,
                name: 'SaleOpp_oppCode',
                parElementId: 1001,
                placeholder: '请输入商机编码',
                wrapperCol: 16,
                megaProps: { span: 2 },
              },
              {
                attrId: 100103,
                dataSource: [
                  {
                    attrId: 100103,
                    attrValue: '1100',
                    attrValueDesc: '',
                    attrValueId: 80230,
                    attrValueName: 'ICT商机',
                    attrValueSort: '1',
                    id: 80230,
                    label: 'ICT商机',
                    statusCd: '1000',
                    value: '1100',
                  },
                  {
                    attrId: 100103,
                    attrValue: '2',
                    attrValueDesc: '',
                    attrValueId: 80231,
                    attrValueName: '一般商机',
                    attrValueSort: '2',
                    id: 80231,
                    label: '一般商机',
                    statusCd: '1000',
                    value: '1000',
                  },
                ],
                busiObjAttrId: 100103,
                busiObjId: '1001',
                span: 8,
                componentType: 'Select',
                disabled: false,
                display: true,
                elementCode: 'SaleOpp_oppType',
                elementId: 100103,
                elementName: '3-商机类型',
                hintInfo: '请选择商机类型',
                initialValue: '1000',
                label: '3-商机类型',
                labelCol: 8,
                name: 'SaleOpp_oppType',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                attrId: 100104,
                busiObjAttrId: 100104,
                busiObjId: '1001',
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_custDecisionPost',
                elementId: 100104,
                elementName: '4-客户决策人职位',
                hintInfo: '',
                initialValue: '',
                label: '4-客户决策人职位',
                labelCol: 8,
                name: 'SaleOpp_custDecisionPost',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                attrId: 100105,
                busiObjAttrId: 100105,
                busiObjId: '1001',
                componentType: 'Input',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppProfit',
                elementId: 100105,
                elementName: '5-商机收益',
                hintInfo: '',
                initialValue: '',
                label: '5-商机收益',
                labelCol: 8,
                name: 'SaleOpp_oppProfit',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                attrId: 100106,
                busiObjAttrId: 100106,
                busiObjId: '1001',
                componentType: 'NumberPicker',
                disabled: false,
                display: true,
                eleAttrs: [],
                elementCode: 'SaleOpp_oppAmount',
                elementId: 100106,
                elementName: '6-商机金额',
                hintInfo: '',
                initialValue: '',
                label: '6-商机金额',
                labelCol: 8,
                name: 'SaleOpp_oppAmount',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
              {
                name: 'ComboModal_name_41174145288',
                icon: 'icon-comboModal',
                label: '查询弹窗',
                componentType: 'ComboModal',
                placeholder: '请选择',
                tableProps: {
                  method: 'post',
                  columns: [
                    {
                      ellipsis: true,
                      title: '处理人',
                      dataIndex: 'dealerName',
                    },
                    {
                      ellipsis: true,
                      title: '销售部门',
                      dataIndex: 'department',
                    },
                    {
                      ellipsis: true,
                      dataIndex: 'roleName',
                      title: '角色',
                    },
                  ],
                  multiple: false,
                  rowKey: 'id',
                  label: 'dealerName',
                  url: '/pmc/pcms/formVersion/queryPageOnline',
                },
                modalProps: {
                  title: '弹窗标题',
                  width: 800,
                },
                initialValue: [{ id: 2539891, dealerName: '关静' }],
                display: true,
                disabled: false,
                required: false,
                span: 8,
                labelCol: 8,
                wrapperCol: 16,
                megaProps: {
                  span: 1,
                },
                rules: {},
              },
              {
                attrId: 100103,
                dataSource: [
                  {
                    attrId: 100103,
                    attrValue: '1100',
                    attrValueDesc: '',
                    attrValueId: 80230,
                    attrValueName: '1111',
                    attrValueSort: '1',
                    id: 80230,
                    label: '1111',
                    statusCd: '1000',
                    value: '1100',
                  },
                  {
                    attrId: 100103,
                    attrValue: '2',
                    attrValueDesc: '',
                    attrValueId: 80231,
                    attrValueName: '2222',
                    attrValueSort: '2',
                    id: 80231,
                    label: '2222',
                    statusCd: '1000',
                    value: '1000',
                  },
                ],
                busiObjAttrId: 100103,
                busiObjId: '1001',
                span: 8,
                componentType: 'Select',
                disabled: false,
                display: true,
                elementCode: 'SaleOpp_select',
                elementId: 100103,
                elementName: 'Select',
                hintInfo: '',
                initialValue: '',
                label: 'Select',
                labelCol: 8,
                name: 'SaleOpp_select',
                parElementId: 1001,
                placeholder: '',
                wrapperCol: 16,
              },
            ],
            wrapperCol: 16,
          },
          {
            name: 'customer',
            attrId: 1,
            busiObjAttrId: 1,
            busiObjId: 1002,
            span: 24,
            componentType: 'Card',
            eleAttrs: [],
            elementCode: 'SaleOpp',
            elementId: 1002,
            elementName: '客户信息',
            label: '客户信息',
            labelCol: 8,
            parElementId: 0,
            placeholder: '',
            wrapperCol: 16,
            properties: [
              {
                name: 'customer_fileName',
                elementId: 38021,
                componentType: 'SlickUpload',
                busiObjAttrId: 10020,
                defaultValue: '',
                display: true,
                extValues: {},
                elementCode: 'customer_fileName',
                statusCd: '1000',
                label: '附件名称',
                parElementId: 38002,
                readOnlyFlag: 0,
                requiredFlag: 0,
                showFlag: 1,
                elementName: '附件名称',
                attrId: 10020,
                busiObjId: 1002,
                disabled: false,
                megaProps: {
                  span: 1,
                },
                uploadProps: {
                  length: 9,
                  size: 10,
                  addUrl: 'pmc/pms/upload/',
                  listType: 'text',
                  deleteUrl: 'pmc/pms/attach/deleteById',
                },
                initialValue: [
                  {
                    attachId: '13004',
                    fileName: '1111.jpg',
                    filePath: 'group1/M00/00/19/rBBRfV8IFWeAP8CKAAAjQfwhQCM706.jpg',
                    url: 'pmc/pms/download/downloadFile.do?id=12002',
                    length: 9025,
                  },
                ],
                rules: {},
              },
            ],
          },
        ],
        submitUrl: '11111',
        saveUrl: '22222222',
        needBack: false,
        vertical: true,
        columnNum: 4,
        formId: 8003,
        formVersionId: 8003,
        labelCol: 8,
        wrapperCol: 16,
      },
    });
  },
  // 按钮组 点击按钮发起确认请求，根据data.ok 决定是否显示弹窗
  'POST /pmc/pcms/formVersion/confirm': (req, res) => {
    res.send({
      success: true,
      stackTrace: null,
      errCode: null,
      errMessage: '',
      data: {
        ok: true,
        reason: '不能新建商机，缺少商机id。',
      },
    });
  },
  // 按钮组 获取按钮列表
  'POST /pmc/pcms/formVersion/buttons': (req, res) => {
    res.send({
      stackTrace: null,
      errCode: null,
      errMessage: '',
      data: {
        total: 3,
        size: 10,
        current: 1,
        records: [
          {
            label: '新增商机1',
            buttonType: 'default',
            action: '/pmc/pcms/formVersion/confirm',
            method: 'post',
            displayMode: 'iframe',
            viewTitle: '我是弹窗1',
            viewWidth: 1200,
            viewHeight: 800,
            viewUrl: 'https://huaban.com/',
          },
          {
            label: '新增商机2',
            buttonType: 'primary',
            action: '/pmc/pcms/formVersion/confirm',
            method: 'post',
            displayMode: 'iframe',
            viewTitle: '我是弹窗1',
            viewWidth: 1200,
            viewHeight: 800,
            viewUrl: 'https://qq.com/',
          },
          {
            label: '新增商机3',
            buttonType: 'dashed',
            action: '/pmc/pcms/formVersion/confirm',
            method: 'post',
            displayMode: 'iframe',
            viewTitle: '我是弹窗1',
            viewWidth: 1200,
            viewHeight: 800,
            viewUrl: 'https://baidu.com/',
          },
        ],
      },
      success: true,
    });
  },
  // combomodal 表格样例数据
  'POST /pmc/pcms/formVersion/queryPageOnline': (req, res) => {
    res.send({
      stackTrace: null,
      errCode: null,
      errMessage: '',
      data: {
        total: 3,
        size: 10,
        current: 1,
        records: [
          {
            id: 2539891,
            dealerName: '关静',
            roleName: '部门经理',
            department: '销售部门',
          },
          {
            id: 2539892,
            dealerName: '张鑫',
            roleName: '副总经理',
            department: '销售部门',
          },
          {
            id: 2539893,
            dealerName: '刘星宇',
            roleName: '总经理',
            department: '销售部门',
          },
        ],
      },
      success: true,
    });
  },
  // 联动时获取select组件的dataSource 样例数据
  'POST /pmc/pcms/formVersion/queryOptions': (req, res) => {
    res.send({
      stackTrace: null,
      errCode: null,
      errMessage: '',
      data: [
        {
          value: 2539891,
          label: '部门经理',
          department: '销售部门',
        },
        {
          value: 2539892,
          label: '副总经理',
          department: '销售部门',
        },
      ],
      success: true,
    });
  },
  'POST /pmc/pcms/formVersion/querySteps': (req, res) => {
    res.send({
      stackTrace: null,
      errCode: null,
      errMessage: '',
      data: {
        current: 1,
        steps: [
          {
            id: 1,
            title: '开始',
            description: '发起人编制创新项目',
          },
          {
            id: 2,
            title: '部门主任审核',
            description: '资料审核',
          },
          {
            id: 3,
            title: '项目效果审核',
            description: '',
          },
          {
            id: 4,
            title: '财务审核',
            description: '',
          },
          {
            id: 5,
            title: '结束',
            description: '',
          },
        ],
      },
      success: true,
    });
  },
  // SlickUpload 样例数据
  'POST /pmc/pcms/formInst/queryForm': (req, res) => {
    res.send({
      stackTrace: null,
      errCode: null,
      errMessage: '',
      data: {
        customer_fileName: [
          {
            attachId: '13004',
            fileName: '222.jpg',
            filePath: 'group1/M00/00/19/rBBRfV8IFWeAP8CKAAAjQfwhQCM706.jpg',
            url: 'pmc/pms/download/downloadFile.do?id=12002',
            length: 9025,
          },
        ],
      },
      success: true,
    });
  },
};

export default delay(proxy, defaultSettings.delay);
